/*
 * SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/*=====================================================================================
 * Description:
 *   The Modbus parameter structures used to define Modbus instances that
 *   can be addressed by Modbus protocol. Define these structures per your needs in
 *   your application. Below is just an example of possible parameters.
 *====================================================================================*/
#ifndef _DEVICE_PARAMS
#define _DEVICE_PARAMS

#include <stdint.h>

//此文件定义了反映对应的modbus地址空间的modbus参数的结构
//对于每种Modbus寄存器类型（线圈，谨慎输入，保留寄存器，输入寄存器）
#pragma pack(push, 1)
typedef struct
{
    uint8_t discrete_input0:1;
    uint8_t discrete_input1:1;
    uint8_t discrete_input2:1;
    uint8_t discrete_input3:1;
    uint8_t discrete_input4:1;
    uint8_t discrete_input5:1;
    uint8_t discrete_input6:1;
    uint8_t discrete_input7:1;
    uint8_t discrete_input_port1:8;
} discrete_reg_params_t; //离散寄存器数据类型
#pragma pack(pop)

#pragma pack(push, 1)
typedef struct
{
    uint8_t coils_port0; // 0
    uint8_t coils_port1; // 1
} coil_reg_params_t;  //线圈寄存器数据类型
#pragma pack(pop)

#pragma pack(push, 1)
typedef struct
{
    float input_data0; // 0
    float input_data1; // 2
    float input_data2; // 4
    float input_data3; // 6
    uint16_t data[150]; // 8 + 150 = 158
    float input_data4; // 158
    float input_data5;
    float input_data6;
    float input_data7;
    uint16_t data_block1[150];
} input_reg_params_t;  //输入寄存器数据类型
#pragma pack(pop)

#pragma pack(push, 1)
typedef struct
{
    float temperature; //意思是：温度 
    float humidity;
    float holding_data2;
    float holding_data3;
    uint16_t test_regs[150];  // 为什么是150个，因为每个寄存器是2个字节，所以150个寄存器就是300个字节
    float holding_data4;
    float holding_data5;
    float holding_data6;
    float holding_data7;
} holding_reg_params_t;  //寄存器数据类型
#pragma pack(pop)

extern holding_reg_params_t holding_reg_params;  //定义一个全局变量，用于存储寄存器数据
extern input_reg_params_t input_reg_params;  //定义一个全局变量，用于存储输入寄存器数据
extern coil_reg_params_t coil_reg_params; //定义一个全局变量，用于存储线圈寄存器数据
extern discrete_reg_params_t discrete_reg_params; //定义一个全局变量，用于存储离散寄存器数据

#endif // !defined(_DEVICE_PARAMS) //如果已经定义了_DEVICE_PARAMS，则不再定义
